//
//  HeightWeightView.m
//  markmap
//
//  Created by 甘世清 on 2024/4/26.
//

#import "HeightWeightView.h"

@implementation HeightWeightView

- (void)SQ_UIViewForSelfView{
    self.backgroundColor = SQColor(@"#4A4A4A");
    self.layer.cornerRadius = 48;
    self.layer.masksToBounds = YES;
    
    HeaderView * xiayibu = [[HeaderView alloc]init];
    xiayibu.image = @"按钮背景";
    xiayibu.text = SQNSLocalString(@"提交");
    xiayibu.colorString = @"#FFFFFF";
    [xiayibu.btn addTarget:self action:@selector(SQ_tijiaoButton) forControlEvents:UIControlEventTouchUpInside];
    xiayibu.font = FONT_MEDIUM(18);
    [self addSubview:xiayibu];
    [xiayibu mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.width.mas_equalTo(SCREEN_WIDETH-60);
        make.height.mas_equalTo(48);
        make.bottom.equalTo(self.mas_bottom).offset(-FootHeight-30);
    }];
    [self addSubview:self.leftLabel];
    [self addSubview:self.rightLabel];
    [self addSubview:self.ttrange];
    
    [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(32);
            make.top.equalTo(self).offset(30);
    }];
    [self.rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.mas_right).offset(-32);
            make.centerY.equalTo(self.leftLabel);
    }];
    [self.ttrange mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.width.mas_equalTo(SCREEN_WIDETH-32);
        make.top.equalTo(self.leftLabel.mas_bottom).offset(16);
        make.height.mas_equalTo(60);
    }];
}
-(void)SQ_tijiaoButton{
   
    [YJProgressHUD SQ_showMsgWithoutView:@""];
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    if (self.isHeight) {
        [dic setObject:[NSString stringWithFormat:@"%.f",self.ttrange.selectedMaximum] forKey:@"height"];
    } else {
        [dic setObject:[NSString stringWithFormat:@"%.f",self.ttrange.selectedMaximum] forKey:@"weight"];
    }
  
    [HttpTool post:Url5 paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        if (self.isheightOrWeightBtnBlock) {
            self.isheightOrWeightBtnBlock();
        }
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
        [YJProgressHUD showMsgWithoutView:httpModel.message];
    }];
}

-(void)SQ_setLines:(BOOL)isHeight right:(NSString*)value{
    self.isHeight = isHeight;
    int height = 45;
    if ([value isNotEmpty]) {
        height = [value intValue];
    }else{
        if (isHeight) {
            height = 170;
        }
    }
    if (isHeight) {
        self.leftLabel .text = SQNSLocalString(@"身高:");
        self.rightLabel.text = [NSString stringWithFormat:@"%dCM",height];
        self.ttrange.maxValue = 230;
        self.ttrange.minValue = 130;
       
    } else {
        self.leftLabel .text = SQNSLocalString(@"体重:");
        self.rightLabel.text = [NSString stringWithFormat:@"%dKG",height];
        self.ttrange.maxValue = 150;
        self.ttrange.minValue = 30;
    }
    self.ttrange.selectedMaximum = height;
    
}
/**
 * Called when the RangeSlider values are changed
 */
-(void)rangeSlider:(TTRangeSlider *)sender didChangeSelectedMinimumValue:(float)selectedMinimum andMaximumValue:(float)selectedMaximum{
    if (self.isHeight) {
        self.rightLabel.text = [NSString stringWithFormat:@"%.fCM",selectedMaximum];
    } else {
        self.rightLabel.text = [NSString stringWithFormat:@"%.fKG",selectedMaximum];
    }
 
}

- (TTRangeSlider *)ttrange{
    if (!_ttrange) {
        _ttrange = [[TTRangeSlider alloc]init];
       
        _ttrange.hideLabels = YES;
        _ttrange.step = 1;
        _ttrange.lineHeight = 6;
        _ttrange.disableRange = YES;
        _ttrange.tintColor = UIColor.whiteColor;
        _ttrange.handleDiameter = 30;
        _ttrange.delegate = self;
        _ttrange.tintColorBetweenHandles = UIColor.whiteColor;
      
    }
    return _ttrange;
}
- (UILabel *)leftLabel{
    if (!_leftLabel) {
        _leftLabel = [[UILabel alloc]init];
        _leftLabel.font = FONT_MEDIUM(16);
        _leftLabel.textColor = UIColor.whiteColor;
        _leftLabel.text = @"身高:";
    }
    return _leftLabel;
}
- (UILabel *)rightLabel{
    if (!_rightLabel) {
        _rightLabel = [[UILabel alloc]init];
        _rightLabel.font = FONT_MEDIUM(16);
        _rightLabel.textColor = UIColor.whiteColor;
        _rightLabel.text = @"170CM";
    }
    return _rightLabel;
}

@end
